﻿<?php
/**
* @version		$Id: view.html.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package		Joomla
* @subpackage	Poll
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Poll component
 *
 * @static
 * @package		Joomla
 * @subpackage	Poll
 * @since 1.0
 */
		
 class amapViewgestdatelivraisonldb extends JView
{
	var $amap;
	function display($tpl = null)
	{
	$mainframe =& JFactory::getApplication();	
		if($this->amap->adLoggue && $mainframe->getUserState("amap_droitAbo", FALSE))
		{
		echo '<div class="amap_bloc">';
			echo '<h5 class="amap_titre">Modification de dates de livraison </h5>';

			$document =& JFactory::getDocument();
			$pathway  =& $mainframe->getPathway();

			// Adds parameter handling
			$params = $mainframe->getParams();

			//Set page title information
			$document->setTitle('Modification de dates de livraisons');

			//Set pathway information
			$pathway->addItem('Gestion des dates de livraison', '');

			$params->def( 'show_page_title', 1 );
			$params->def( 'page_title', 'adhésion');
			
			// charge les abonnements et renvoie nombre d'abonnement liés à chaque statut
$user =& JFactory::getUser();
$userId = $user->get( 'id' ); 
$db = JFactory::getDBO();

    $sql=$db->getQuery(true);

//SELECT distinct date,nomAbonnement from amap_jourdistributionabonnement inner join amap_abonnement on amap_jourdistributionabonnement.nomAbonnement=amap_abonnement.nom where date >curdate() and Periodicite='$periodicite' order by date, Periodicite LIMIT 40


//liste des noms de contrats dont l'utilisateur est personne relai

        $sql="select relai1,relai2,relai3,relai4,relai5,relai6,relai7,relai8,relai9,relai10 from amap_adherent where amap_adherent.IDJ = $userId";

//$sql="SELECT distinct date,nomAbonnement from amap_jourdistributionabonnement inner join amap_abonnement on amap_jourdistributionabonnement.nomAbonnement=amap_abonnement.nom where date >curdate() and (amap_adherent.relai1=$userId or amap_adherent.relai2=$userId or amap_adherent.relai3=$userId or amap_adherent.relai4=$userId or amap_adherent.relai5=$userId";
	$db->setQuery( $sql);
    $relais=$db->loadAssoc();

//var_dump( $relais);
//echo"<br>--------------<br>";
//echo"------------------------------------------<br>";
//var_dump($relais);

//echo "user $user  userId  $userId<br>";
//echo "relai1 ".$relais['relai1']."<br>";
//echo "relai2 ".$relais['relai2']."<br>";
//echo "relai3 ".$relais['relai3']."<br>";
//echo "relai4 ".$relais['relai4']."<br>";
//echo "relai5 ".$relais['relai5']."<br>";
if($relais['relai1']=="tous"){$sql="SELECT  date,nomAbonnement from amap_jourdistributionabonnement  where date > curdate() ";}
else
{
$sql="SELECT  date,nomAbonnement from amap_jourdistributionabonnement
where date > curdate() and 
(nomAbonnement='".$relais['relai1']."' 
or nomAbonnement='".$relais['relai2']."'  
or nomAbonnement='".$relais['relai3']."'  
or nomAbonnement='".$relais['relai4']. "'  
or nomAbonnement='".$relais['relai5']."' 
or nomAbonnement='".$relais['relai6']."' 
or nomAbonnement='".$relais['relai7']."' 
or nomAbonnement='".$relais['relai8']."' 
or nomAbonnement='".$relais['relai9']."' 
or nomAbonnement='".$relais['relai10']."')";
}
$db->setQuery( $sql);
    $listedates=$db->query();
//var_dump( $listedates);
echo "<br><br>";
echo "<TABLE BORDER='1'>";
echo  "<TR><TD>Nom du contrat</TD><TD>Date programmée</TD><TD>Date modifiée (au format JJ/MM/AAAA): <br>par exemple 17/10/2014 pour le 17 Octobre 2014</TD></TR>";			
foreach($listedates as $ligne) 
{
//var_dump( $ligne);
$abo=$ligne['nomAbonnement'];
$date_ancienne=$ligne['date'];
//echo "<TR><FORM name='toto' action='?task=modifDateLivraisonldb' ><TD>".$ligne['nomAbonnement'] . "</TD><TD>".fdate($ligne['date']) . "</TD><TD><input type='text' name='date1'><a href='?task=modifDateLivraisonldb&date=$date_ancienne&date='date1'' id='link'>Validation</a> </TD></TR></FORM>";
echo "<TR valign='top'><TD>".$abo."</TD><TD>".fdate($date_ancienne). "</TD><TD ><FORM  name='toto' action='?task=modifDateLivraisonldb' method='POST' ><input type='date' name='date1'> <input type='hidden' name='abo' value='$abo' ><input type='hidden' name='dateancienne' value='$date_ancienne' ><input type = 'submit' value = 'Valider'></FORM></TD></TR>";


}

echo "</TABLE>";
echo "Remarque: Pour ajouter ou supprimer une date de livraison, faire un couriel a admin@amapluydebearn.org. Merci"; 

		}
//JRequest::setCmd( 'layout', $template );		
parent::display($tpl);
	}
}
?>
